package com.hex.ds.hdtp.core.inf.script.transfer.repository.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hex.ds.hdtp.core.inf.common.page.Page;
import com.hex.ds.hdtp.core.inf.common.page.converter.IPageAndMyBatisPlusPageConverter;
import com.hex.ds.hdtp.core.inf.script.transfer.mapper.IScriptConvertTaskMapper;
import com.hex.ds.hdtp.core.inf.script.transfer.po.ScriptConvertTaskPo;
import com.hex.ds.hdtp.core.inf.script.transfer.repository.IScriptConvertTaskRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.inf.script.transfer.repository.impl
 * @ClassName ScriptConvertTaskRepository
 * @Description: 脚本转换任务-数据服务接口实现
 * @Author: wz.li
 * @Date 2023/2/12 10:25
 * @Version v2.0.2
 **/
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScriptConvertTaskRepository implements IScriptConvertTaskRepository {

    private final IScriptConvertTaskMapper scriptConvertTaskMapper;

    private final IPageAndMyBatisPlusPageConverter pageConverter;

    /*
     * @Method: queryById <br>
     * @Param: [pkId] <br>
     * @Return: com.hex.ds.hdtp.core.inf.script.transfer.po.ScriptConvertTaskPo <br>
     * @Description：根据主键查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/2/12 10:25 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public ScriptConvertTaskPo queryById(String pkId) {
        return scriptConvertTaskMapper.selectById(pkId);
    }

    /*
     * @Method: add <br>
     * @Param: [scriptConvertTaskPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：新增<br>
     * @Author： wz.li<br>
     * @Date： 2023/2/12 10:25 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer add(ScriptConvertTaskPo scriptConvertTaskPo) {
        return scriptConvertTaskMapper.insert(scriptConvertTaskPo);
    }

    /*
     * @Method: modifyById <br>
     * @Param: [scriptConvertTaskPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键更新<br>
     * @Author： wz.li<br>
     * @Date： 2023/2/12 10:25 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer modifyById(ScriptConvertTaskPo scriptConvertTaskPo) {
        return scriptConvertTaskMapper.updateById(scriptConvertTaskPo);
    }

    /*
     * @Method: removeById <br>
     * @Param: [pkId] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键删除<br>
     * @Author： wz.li<br>
     * @Date： 2023/2/12 10:25 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer removeById(String pkId) {
        return scriptConvertTaskMapper.deleteById(pkId);
    }

    /*
     * @Method: queryListByPage <br>
     * @Param: [scriptConvertTaskPo, page] <br>
     * @Return: com.hex.ds.hdtp.core.inf.common.page.Page<com.hex.ds.hdtp.core.inf.script.transfer.po.ScriptConvertTaskPo> <br>
     * @Description：分页查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/2/12 10:26 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Page<ScriptConvertTaskPo> queryListByPage(ScriptConvertTaskPo scriptConvertTaskPo, Page page) {
        final IPage tmpPageResult = scriptConvertTaskMapper.queryListByPage(
                pageConverter.toMyBatisPlusPage(page)
                , scriptConvertTaskPo
        );
        final List list = tmpPageResult.getRecords();
        final Page pageResult = pageConverter.toPage(tmpPageResult);
        return pageResult.setData(list);
    }

    @Override
    public void modifySuccessNum(String pkId) {
        scriptConvertTaskMapper.modifySuccessNum(pkId);
    }

    @Override
    public void modifyFailNum(String pkId) {
        scriptConvertTaskMapper.modifyFailNum(pkId);
    }

    @Override
    public void modifyStatus(String pkId) {
        scriptConvertTaskMapper.modifyStatus(pkId, DateUtil.now());
    }

    /**
     * @Method modifyTaskStart
     * @Param pkId
     * @Param status
     * @Return java.lang.Integer
     * @Description 更新启动任务时状态、成功失败数、开始时间
     * @Author gj.xu
     * @Date 2024/1/8 11:48
     * @Version V2.0
     */
    @Override
    public Integer modifyTaskStart(String pkId, String status) {
        return scriptConvertTaskMapper.modifyTaskStart(pkId, status, DateUtil.now());
    }

}
